package com.ruoyi.zuzhi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zuzhi.domain.WorkLocation;
import com.ruoyi.zuzhi.service.IWorkLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司工作地点信息Controller
 * 
 * @author lgr
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/zuzhi/location")
public class WorkLocationController extends BaseController
{
    @Autowired
    private IWorkLocationService workLocationService;

    /**
     * 查询公司工作地点信息列表
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkLocation workLocation)
    {
        startPage();
        List<WorkLocation> list = workLocationService.selectWorkLocationList(workLocation);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出公司工作地点信息列表
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:location:export')")
    @Log(title = "公司工作地点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkLocation workLocation)
    {
        List<WorkLocation> list = workLocationService.selectWorkLocationList(workLocation);
        ExcelUtil<WorkLocation> util = new ExcelUtil<WorkLocation>(WorkLocation.class);
        util.exportExcel(response, list, "公司工作地点信息数据");
    }

    /**
     * 获取公司工作地点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:location:query')")
    @GetMapping(value = "/{posId}")
    public AjaxResult getInfo(@PathVariable("posId") Long posId)
    {
        return success(workLocationService.selectWorkLocationByPosId(posId));
    }

    /**
     * 新增公司工作地点信息
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:location:add')")
    @Log(title = "公司工作地点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkLocation workLocation)
    {
        return toAjax(workLocationService.insertWorkLocation(workLocation));
    }

    /**
     * 修改公司工作地点信息
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:location:edit')")
    @Log(title = "公司工作地点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkLocation workLocation)
    {
        return toAjax(workLocationService.updateWorkLocation(workLocation));
    }

    /**
     * 删除公司工作地点信息
     */
    @PreAuthorize("@ss.hasPermi('zuzhi:location:remove')")
    @Log(title = "公司工作地点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{posIds}")
    public AjaxResult remove(@PathVariable Long[] posIds)
    {
        return toAjax(workLocationService.deleteWorkLocationByPosIds(posIds));
    }
}
